<?php
    namespace Home\Controller;
    use Think\Controller;
    class TeshugongzuoliangController extends Controller {
    
    public function _initialize()
    {
        header("Access-Control-Allow-Origin: *");  

        header("Access-Control-Allow-Credentials: true"); 
      
        header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS"); //允许的请求类型
        
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept"); 

    }

    public function get_list()
    {
        $page = I("get.page");
        $limit = I("get.limit");

        $data = M("cbhs.rbrvs_distribution_calc_dept")->limit(($page-1)*$limit,$limit)->select();
        
        $json["data"] = $data;
        $json["code"] = 0;
        $json["count"] = M("cbhs.rbrvs_distribution_calc_dept")->count();
        $json["msg"] = "";
        
        $this->ajaxReturn($json,"json");
    }

    public function get_one()
    {
        $uuid = I("post.uuid");

        $info = M("cbhs.rbrvs_distribution_calc_dept")->where("uuid = '$uuid'")->find();
        $json["data"]   = $info;
        $json["code"]   = 0;
        $json["msg"]    = "";

        $this->ajaxReturn($json,"json");
    }

    public function save_one()
    {
        $data = I("post.");
        $uuid = $data["uuid"];
        unset($data["uuid"]);

        $result = M("cbhs.rbrvs_distribution_calc_dept")->where("uuid = '$uuid'")->save($data);
        if($result !== false)
        {
            $json["code"] = 0;
            $json["msg"] = "修改成功";
        }
        else
        {
            $json["code"] = -1;
            $json["msg"] = "修改失败";
        }
 
        $this->ajaxReturn($json,"json");
    }

    public function add_one()
    {
        $data = I("post.");
        $data['uuid'] = uuid();
        $result = M("cbhs.rbrvs_distribution_calc_dept")->add($data);
        if($result !== false)
        {
            $json["code"] = 0;
            $json["msg"] = "添加成功";
        }
        else
        {
            $json["code"] = -1;
            $json["msg"] = "添加失败";
        }
 
        $this->ajaxReturn($json,"json");
    }

    public function get_dept_list()
    {
        $list = M("comm.sys_dept_dict")->select();
        $json["data"]   = $list;
        $json["code"]   = 0;
        $json["msg"]    = "";
        $this->ajaxReturn($json,"json");
    }
	
	public function get_perform_dept_list()
	{
	    $list = M("comm.sys_dept_dict")->where('attr = 1')->select();
	    $json["data"]   = $list;
	    $json["code"]   = 0;
	    $json["msg"]    = "";
	    $this->ajaxReturn($json,"json");
	}
	
	public function get_item_class_list()
	{
	    $list = M("hisdata.price_list")->where('price >100')->field('item_code,item_name')->select();
	    $json["data"]   = $list;
	    $json["code"]   = 0;
	    $json["msg"]    = "";
	    $this->ajaxReturn($json,"json");
	}


    public function create_data()
    {
    	$data = I('post.');
        $data['date'] = date("Ym",strtotime($data['date']));

        //建立数据库连接
        $user = "system";                //数据库用户名
        $password = "123456";            //密码
        $conn_str = "(DESCRIPTION=(ADDRESS=(PROTOCOL =TCP)(HOST=localhost)(PORT = 1521))(CONNECT_DATA =(SID=orcl)))";          //连接串(cstr : Connection_STRing)
        $remote = true;                  //是否远程连接
        if ($remote) 
        {
          $conn = OCILogon($user, $password, $conn_str);
        }
        else 
        {
          $conn = OCILogon($user, $password);
        }//设定绑定
        $id = 5;                        //准备用以绑定的php变量 id
        $name = "";                     //准备用以绑定的php变量 name/** 调用存储过程的sql语句(sql_sp : SQL_StoreProcedure)
        //  *  语法：
        //  *      BEGIN 存储过程名([[:]参数]); END;
        //  *  加上冒号表示该参数是一个位置
        // **/
        $sql_sp = "BEGIN cbhs.SP_INCOME_AUTO_ACC(:date); END;";
        //Parse
        $stmt = OCIParse($conn, $sql_sp);//执行绑定
        OCIBindByName($stmt, ":date", $data['date'], 16);           //参数说明：绑定php变量$id到位置:id，并设定绑定长度16位Execute
        OCIExecute($stmt);

        $sql_sp = "BEGIN cbhs.SP_INCOME_AUTO_HOS_ACC(:date); END;";
        //Parse
        $stmt = OCIParse($conn, $sql_sp);//执行绑定
        OCIBindByName($stmt, ":date", $data['date'], 16);           //参数说明：绑定php变量$id到位置:id，并设定绑定长度16位Execute
        OCIExecute($stmt);
        
        echo 1;
    }

}